package cn.swing.ui;

import lombok.Getter;
import javax.swing.*;
import java.awt.event.*;

/**
 * @author xbsoft2
 */
public final class Error extends JDialog {
  private JPanel contentPane;
  private JButton buttonOK;
  private JButton buttonCancel;
  @Getter
  private JTextPane textArea;
  public Error(String text) {
    setContentPane(contentPane);
    setModal(true);
    getRootPane().setDefaultButton(buttonOK);
    buttonOK.addActionListener(e -> System.exit(0));
    buttonCancel.addActionListener(e -> System.exit(0));
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    contentPane.registerKeyboardAction(e -> System.exit(0), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    init(text);
  }
  private void init(String text) {
    textArea.setAutoscrolls(Boolean.TRUE);
    textArea.setText(text);
    this.setTitle("错误");
    this.setBounds(300,300,500,300);
    this.setVisible(Boolean.TRUE);
  }

}
